package com.ruoyi.bl.controller;

import com.ruoyi.bl.domain.BlActivity;
import com.ruoyi.bl.service.IBlActivityService;
import com.ruoyi.bl.tools.OssUp;
import com.ruoyi.bl.tools.RequestAsk;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动模块Controller
 *
 * @author ruoyi
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/bl/activity")
public class BlActivityController extends BaseController {
    @Autowired
    private IBlActivityService blActivityService;

    /**
     * 查询活动模块列表
     */
    @GetMapping("/list")
    public TableDataInfo list(BlActivity blActivity) {
        startPage();
        List<BlActivity> list = blActivityService.selectBlActivityList(blActivity);
        return getDataTable(list);
    }

    /**
     * 导出活动模块列表
     */
    /*@PreAuthorize("@ss.hasPermi('bl:activity:export')")*/
    @Log(title = "活动模块", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlActivity blActivity) {
        List<BlActivity> list = blActivityService.selectBlActivityList(blActivity);
        ExcelUtil<BlActivity> util = new ExcelUtil<BlActivity>(BlActivity.class);
        util.exportExcel(response, list, "活动模块数据");
    }

    /**
     * 获取活动模块详细信息
     */
    /* @PreAuthorize("@ss.hasPermi('bl:activity:query')")*/
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId) throws Exception {
        //requestAsk.ask("你好");点开某个活动时候,进行ai介绍
        return success(blActivityService.selectBlActivityByActivityId(activityId));
    }

    /**
     * 新增活动模块
     */
    @Log(title = "活动模块", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlActivity blActivity) {
        // 上传图片功能,获得url,赋值存入数据库
        //String s = ossUp.OSs(file);
        //blActivity.setPicture(s);
        return toAjax(blActivityService.insertBlActivity(blActivity));
    }

    /**
     * 修改活动模块
     */
    /*@PreAuthorize("@ss.hasPermi('bl:activity:edit')")*/
    @Log(title = "活动模块", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlActivity blActivity) {
        return toAjax(blActivityService.updateBlActivity(blActivity));
    }

    /**
     * 删除活动模块
     */
    /*@PreAuthorize("@ss.hasPermi('bl:activity:remove')")*/
    @Log(title = "活动模块", businessType = BusinessType.DELETE)
    @DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds) {
        return toAjax(blActivityService.deleteBlActivityByActivityIds(activityIds));
    }
}
